package com.wwj.auction.admin.controller;


import com.wwj.auction.admin.entity.Store;
import com.wwj.auction.admin.entity.vo.PageModel;
import com.wwj.auction.admin.entity.vo.ShopVo;
import com.wwj.auction.admin.service.ShopService;
import com.wwj.auction.common.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wwj
 * @since 2021-08-29
 */
@RestController
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    /**
     * 获取商品列表
     *
     * @return
     */
    @GetMapping("/list/{page}/{limit}")
    public R list(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit) {
        PageModel<ShopVo> pageModel = shopService.listForShop(page, limit);
        return R.ok().data("pageModel", pageModel);
    }

    /**
     * 查询指定店铺的商品列表
     *
     * @param storeId
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list/{storeId}/{page}/{limit}")
    public R listByStoreId(
            @PathVariable("storeId") Integer storeId,
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit) {
        PageModel<ShopVo> pageModel = shopService.listByStoreId(storeId, page, limit);
        return R.ok().data("pageModel", pageModel);
    }

    /**
     * 提供远程调用
     * 根据商品id得到所属的店铺信息
     *
     * @param shopId
     * @return
     */
    @GetMapping("/get/store/name/{shopId}")
    public R getStoreName(@PathVariable("shopId") Integer shopId) {
        Store store = shopService.getStoreName(shopId);
        return R.ok().data("store", store);
    }
}

